#include <cassert>
#include <vector>

using namespace std;

class Solution {
public:
    int findPeakElement(vector<int>& nums) {
        int left = -1, right = nums.size() - 1;
        while (left + 1 < right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] > nums[mid + 1]) {
                right = mid;
            } else {
                left = mid;
            }
        }
        return right;
    }
};

int main() {
    Solution s;

    vector<int> nums1{1, 2, 3, 1};
    vector<int> nums2{1, 2, 1, 3, 5, 6, 4};

    assert(s.findPeakElement(nums1) == 2);
    assert(s.findPeakElement(nums2) == 5);
}